/*
 * main.cpp
 *Creational Pattern: SINGLETON
 *  Created on: Sep 14, 2011
 *      Author: gassa
 */

#include <iostream>
#include <fstream>
#include <map>
#include <vector>
#include <utility>
#include "../include/CUtilities.h"
#include "../include/config.h"

using namespace std;

#ifndef TERMDICTBUILDER_H_
#define TERMDICTBUILDER_H_

struct valueType{
  size_t id;
  int count;

  valueType(const size_t _id,const int _count) : id(_id),count(_count){}
};

typedef map<string, valueType> MAPTYPE;

class TermDictBuilder
{
private:
    static bool instanceFlag;
    static TermDictBuilder *builderInstance;
    MAPTYPE termMap;
    MAPTYPE rawDataMap;
    size_t termId;
    size_t rawDataId;
    int barralId;
    int count;
    TermDictBuilder(){
        //private constructor
        instanceFlag = true;
    	count = 0;
        termId = 0;
        rawDataId = 0;
        barralId = 0;
    }
public:
    ~TermDictBuilder(){
            instanceFlag = false;
            delete builderInstance;
    }
    static TermDictBuilder* getInstance();
    size_t addTermToMap(string key);
    size_t addTermToMapNoCount(string key);
    void addRawDataToMap(string key);
    void writeTermTofile();
    void writeRawDataToFile();
    void createRawDataTempFile();
    void megerRawDataToFile();
    void generateFinalRawDataFile();
    void printMap();
    bool isRawDataMapFull();
    void setOffsetByTerm(string term);
};

#endif
